package com.example.base.security.util;

import com.example.base.security.SysUser;
import com.example.base.security.domain.SysUserEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @Classname SecurityUtil
 * @Description TODO
 * @Date 2023/9/17 3:06
 * @Created by XiongXiong
 * @Author: X.I.O
 */
public class SecurityUtil {

    public static SysUser getSelfUserEntity(){
        Authentication authentication= SecurityContextHolder.getContext().getAuthentication();
        if(authentication==null){
            return null;
        }
        if(authentication.getPrincipal()==null){
            return null;
        }
        if(authentication.getPrincipal() instanceof SysUser){
            return  (SysUser) authentication.getPrincipal();
        }
        return null;
    }
}
